<?php


namespace app\admin\controller;
use app\admin\model\Foods as FoodsModel;
use app\admin\model\Forms as FormsModel;
use think\Controller;

/**
 * 订单管理类
 *
 */
class Forms extends Controller
{
    /**
     * 订单归集显示页面
     *
     */
   public function listpage()
    {
        $model = new FormsModel();
        $data = $model->getlist();
        $this->assign('data',$data);
        return $this->fetch();
    }
    /**
     * 接收删除订单时主键并对数据库操作
     *
     */
    public function del($no){
        $model = new FormsModel();
        $ip = $model->delOrder($no);
        if($ip){
            return alert_success('删除数据成功!','Forms/listpage');
        }else{
            return alert_error('删除数据失败!');
        }
    }

    /* 订单详情 */
  public  function details($no)
    {
        $model = new FormsModel();
        $data = $model->getFdetails($no);
        $sdata = $model->getDe($no);
        $model1 = new FoodsModel;
        $fdata=$model1->getFodetail();
        $sum = 0;
        foreach ($sdata as $card) {
            $sum += ($card['nprice'] * $card['foods_number']);
//        $this->assign('data',$data);
//        $this->assign('sdata',$sdata);
  }
            return $this->fetch('details', compact('sdata', 'data', 'sum','fdata'));
        }

    //新订单
   public function new_forms()
    {
        $model = new FormsModel();//未完成订单
        $data = $model->getNforms();
        $this->assign('data', $data);
        return $this->fetch();
    }
   public function code($no){
       $arr = [];
       for($i=0;$i<2;$i++){
           $arr[$i] = chr(mt_rand(65,90)).chr(mt_rand(48,57));
       }
       $code = implode('',$arr);
       $model=new FormsModel();
       $res=$model->updateCode($code,$no);
       if($res){
           $this->assign('code',$code);
           return $this->fetch();
       }
   }

}